package main

import (
	"fmt"
	"os"

	"gddgame.cc/galaxy"
	"gddgame.cc/galaxy/binocle/galaxy_provide"
	"gddgame.cc/galaxy/common/bootstrap"
	"gddgame.cc/galaxy/common/feature/dwarf"
	"gddgame.cc/galaxy/project/maze/maze"
	"gddgame.cc/galaxy/project/maze/maze/cmd/generate"
)

func main() {

	galaxy.AttachCommand(dwarf.Root)
	// 设置命令信息
	dwarf.SetInfo("Maze Game", "迷宫闯闯闯游戏服务器", maze.Version)
	// 配置文件设置
	dwarf.BindBase("config", []string{"~", "."})
	dwarf.AddCommand(generate.Command)

	dwarf.PersistentPostRun(func() error {
		return galaxy.PreStart(bootstrap.DefaultBoot.ParseConfig)
	}, func() error {
		return galaxy.Start(registerBinocle, register)
	})
	if err := galaxy.Init(nil); err != nil {
		fmt.Fprint(os.Stderr, err)
		fmt.Print("\n")
		os.Exit(1)
	}
}

func register() error {
	component := &maze.Component{Config: &maze.Config{}}

	return galaxy.RegisterServer(galaxy.ServerProvider{
		Name:   "maze",
		Config: component.Config,
		Inject: component,
		OnCreate: func() error {
			component.Component(component)
			return nil
		},
		OnStop: func() error {
			return component.Nebula.Close()
		},
	})
}
func registerBinocle() error {
	return galaxy.RegisterServer(galaxy_provide.AgentProvide())
}
